package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;

    // 查询通用设置
    @GetMapping("/users/settings")
    public ResponseEntity findSettingVo() {
        // 调用manager
        return settingManager.findSettingVo();
    }

    // 设置陌生人问题
    @PostMapping("/users/questions")
    public void setQuestion(@RequestBody Map<String, String> param) {
        // 1.接收参数
        String content = param.get("content");
        // 2.调用manager
        settingManager.setQuestion(content);
    }

    // 设置推送通知
    @PostMapping("/users/notifications/setting")
    public void setNotification(@RequestBody Notification param) {
        // 调用manager
        settingManager.setNotification(param);
    }

    // 黑名单分页查询
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackListByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return settingManager.findBlackListByPage(pageNum, pageSize);
    }

    // 移除黑名单
    @DeleteMapping("/users/blacklist/{blackUserId}")
    public void deleteBlackList(@PathVariable Long blackUserId){
        // 调用manager
        settingManager.deleteBlackList(blackUserId);
    }


    @PostMapping("/users/phone/sendVerificationCode")
    public void sendSmsUpdatePhone() {
        // 调用manager
        settingManager.updatePhoneSendSms();
    }


    //修改手机号 - 2 校验验证码
    @PostMapping("/users/phone/checkVerificationCode")
    public ResponseEntity verifyUpdatePhone(@RequestBody Map<String, String> param) {
        // 1.接收请求参数
        String verificationCode = param.get("verificationCode");
        // 调用manager
        ResponseEntity responseEntity = settingManager.verifyUpdatePhone(verificationCode);
        return responseEntity;
    }

    //修改手机号 - 3 保存
    @PostMapping("/users/phone")
    public void saveUpdatePhone(@RequestBody Map<String, String> param) {
        // 1.接收请求参数
        String mobile = param.get("phone");
        // 调用manager
        settingManager.saveUpdatePhone(mobile);
    }
}
